package m1_simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/*
    生产者
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.建立连接
        ConnectionFactory f =  new ConnectionFactory();
        //2.定义队列(在你的rebbitMQ服务器上消息发送到哪个队列上)
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        f.setVirtualHost("/css");
        Connection con = f.newConnection();
        Channel c = con.createChannel();
        //3.发送消息
        c.queueDeclare("helloworld",
                        false,
                        false,
                        false,
                        null);
        c.basicPublish("",
                        "helloworld",
                        null,
                        "Hello World".getBytes("UTF-8"));
        System.out.println("消息已发送");
        //4.断开连接
        c.close();
    }
}
